function page(p){
		$.ajax({
			url : "system/loadSystem.sls",
			type : "post",
			data : {"page":p},
			dataType : "json",
			success : function(result) {
				$("#tbody").empty();
				if(result.status == 0){
					var coms = result.data;
					for(var i=0;i<coms.length;i++){
						var companyId = coms[i].companyId;
						var s = '<tr><td>'+coms[i].title+'</td><td>'+coms[i].comdate+'</td>'+
						'<td><a href="javascript:index_modify('+companyId+');" class="ico edit">修改</a></td>'+
						'<td><a href="javascript:index_delet('+companyId+');" class="ico del">删除</a></td>'+
						'</tr>';
						var $tr = $(s);
						$tr.data("companyId",companyId);
						$("#tbody").append($tr);
					}

					$.ajax({
						url : "system/page.sls",
						type : "post",
						dataType : "json",
						success : function(result) {
							if(result.status == 0 ){
								var page = result.data.page;
								var total = result.data.total;
								var top ;
								var end ;
								var pageBody = "";
								if(page == 1){
									top = '<a>上一页</a>';
								} else {
									top = '<a href="javascript:page('+(page-1)+');">上一页</a>';
								}
								if(page == total){
									end = '<a>下一页</a>';	
								} else {
									end = '<a href="javascript:page('+(page+1)+');">下一页</a>';
								}
								var i=1;
								var m=3;
								if(page>1){
									i = page-1;
									m = page+1;
								}
								if(m>total){
									i--;
									m = total;
								}
								if(i==0){
									i=1;
								}
								for( i;i<=m;i++){
									if(i==page){
										pageBody+='<a href="javascript:page('+i+');" style="font-weight:bold;color:#8d341f;">'+i+'</a>';
									} else {
										pageBody+='<a href="javascript:page('+i+');">'+i+'</a>';
									}
								}
								var s = top+pageBody+end;									
								$("#index_page").html(s);
							}
						},
						error : function(){
							window.location.href="error.sls";
						}
					});
				}
				
			},
			error : function(){
				window.location.href="error.sls";
			}
		});
}

function index_delet(id){
	var boo = window.confirm("确定删除此条动态?");
	if(boo){
		$.ajax({
			url : "system/deleteCompanyInfo.sls",
			type : "post",
			data : {"id":id},
			success : function(result){
				if(result.status == 0){
					var p = result.data;
					page(p);
				}
			},
			error : function(){
				window.location.href="error.sls";
			}
		});
	}
}

function index_modify(id){
	$("#manage_list").hide();
	$("#manage_modify").fadeIn();
	$.ajax({
		url : "system/companyInfo.sls",
		type : "post",
		data : {"id":id},
		success : function(result){
			if(result.status == 0){
				var com = result.data;
				$("#index_modify_title").val(com.title);
				$("#index_modify_date").val(com.comdate);
				$("#index_modify_content").val(com.detail);
				$("#index_modify_title").data("companyId",com.companyId);
			}
		},
		error :function(){
			window.location.href="error.sls";
		}
	});
}

function index_modify_back(p){
	$("#index_modify_error").html("");
	$("#manage_modify").hide();
	$("#manage_list").fadeIn();
	page(p);	
}

function index_modify_submit(){
	var title = $("#index_modify_title").val();
	var comdate = $("#index_modify_date").val();
	var detail = $("#index_modify_content").val();
	var companyId = $("#index_modify_title").data("companyId");
	if(comdate == "" || title == "" ){
		$("#index_modify_error").html("标题或日期不能为空!");
		return;
	}
	$("#manage_list").hide();
	$("#manage_modify").fadeIn();
	$.ajax({
		url : "system/updateCompanyInfo.sls",
		type : "post",
		data : {
			"companyId":companyId,"title":title,"comdate":comdate,"detail":detail
			},
		success : function(result){
			if(result.status == 0){
				var p = result.data;
				$("#index_modify_error").html("保存成功!");
				setTimeout(function(){
					index_modify_back(p);
				},1000);
			}
		},
		error : function (){
			window.location.href="error.sls";
		}
		
		
	});
}











	